package com.dbh.company.freeform.platform;

import cn.hutool.core.convert.Convert;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.sax.handler.MapRowHandler;
import com.dbh.company.util.EncryptUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 注册相关接口功能
 * @author dongbanghui
 * @create 2023/2/22
 */
public class Register {

    public static void registerPerson() {
        // 解析excel文件
        String application = "freeform_demo";
        String ak = "bfakalxqjoa7p7532mtw";
        int cardType = 0;
        String excelPath = "F:\\temp\\6044_e_contract_20230222102108_数据导出结果.xlsx";
        MapRowHandler mapRowHandler = new MapRowHandler(0, 1, 47) {
            @Override
            public void handleData(int sheetIndex, long rowIndex, Map<String, Object> data) {
                String name = Convert.toStr(data.get("name"));
                String cardCode = Convert.toStr(data.get("card_code"));
                HashMap<String, Object> paramMap = new HashMap<>();
                paramMap.put("application", application);
                paramMap.put("cardCode", cardCode);
                paramMap.put("cardType",  cardType);
                paramMap.put("kafkaMessage", 1);
                paramMap.put("name", name);
                paramMap.put("formId", 71750);
                paramMap.put("subjectType", 1);
                // 调用接口
                String urlParam = "ak=" + ak + "&application=" + application;
                String queryParam = EncryptUtil.DESEncrypt2("abcqwertty", urlParam);
                String url = "https://contract-front.ke.com/third/webApi/loadBridge/subjectAdd?info=" + queryParam;
                HttpResponse execute = HttpRequest.post(url)
                        .body(JSONUtil.toJsonStr(paramMap), "application/json")
                        .timeout(3000)
                        .execute();
                System.out.println(execute.body());
            }
        };
        ExcelUtil.readBySax(excelPath, 0, mapRowHandler);
    }

    public static void main(String[] args) {
        registerPerson();
    }

}
